﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using Lswweb.Model;
using Lswweb.Domain;

namespace Lswweb.Controls
{
    public class UserMembership : SkinnedWebControl
    {
        #region 成员字段和构造方法

        private TextBox txtUserName;
        private TextBox txtPsw;
        private TextBox txtPsw2;
        private TextBox txtEmail;
        private DropDownList ddlDescribes;
        private QuestionDropDownList ddlPasswordQuestion;
        private TextBox txtAnswer;

        #endregion

        protected override void InitializeSkin(System.Web.UI.Control skin)
        {
            txtUserName = (TextBox)skin.FindControl("txtUserName");
            txtPsw = (TextBox)skin.FindControl("txtPsw");
            txtPsw2 = (TextBox)skin.FindControl("txtPsw2");
            txtEmail = (TextBox)skin.FindControl("txtEmail");
            ddlPasswordQuestion = (QuestionDropDownList)skin.FindControl("ddlPasswordQuestion");
            txtAnswer = (TextBox)skin.FindControl("txtAnswer");
            ddlDescribes = skin.FindControl<DropDownList>("ddlDescribes");
        }

        #region 共公属性

        public UserInfo MembershipInfo
        {
            get 
            {
                UserInfo membership = new UserInfo();
                membership.Id = UserId;
                membership.LoginName = txtUserName != null ? txtUserName.Text.Trim() : txtEmail.Text.Trim();
                membership.Password = txtPsw.Text.Trim();
                membership.PasswordQuestion = ddlPasswordQuestion.SelectedValue;
                membership.PasswordAnswer = txtAnswer.Text.Trim();
                membership.Email = txtEmail.Text.Trim();
                membership.LastLoginDate = DateTime.Now;
                membership.DateCreated = DateTime.Now;
                membership.Describes = ddlDescribes.SelectedValue;
                return membership;
            }
        }


        private int UserId
        {
            get { return SiteContext.Current.Id; }
        }
        #endregion

        protected override string DefaultSkinFilename
        {
            get { return "User/UserMembership.ascx"; }
        }
    }
}
